package cn.mill.demo.api;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.ContextStartedEvent;
import org.springframework.context.event.ContextStoppedEvent;

public class SpringApplicationListener implements ApplicationListener<ApplicationEvent> {
  private static Logger logger = LoggerFactory.getLogger(SpringApplicationListener.class);

  @Override
  public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ContextClosedEvent) {
      // http://www.cnblogs.com/beautiful-scenery/p/3588834.html
      logger.info("------------------------------------------------------");
      logger.info("************ SpringBoot 容器已经关闭！*********************");
      logger.info("------------------------------------------------------");
    }
    if (event instanceof ContextRefreshedEvent) {
      logger.info("------------------------------------------------------");
      logger.info("************ SpringBoot 容器初始完成！*********************");
      logger.info("------------------------------------------------------");
    }
    if (event instanceof ContextStartedEvent) {
      logger.info("======================================================");
      logger.info("************ SpringBoot 容器已经启动！*********************");
      logger.info("======================================================");
    }
    if (event instanceof ContextStoppedEvent) {
      logger.info("------------------------------------------------------");
      logger.info("************ SpringBoot 容器已经停止！*********************");
      logger.info("------------------------------------------------------");
    }
  }
}
